function cancel(){
	$("#dialog-line").fadeOut(100);
	$("#dialog-pay").fadeOut(100);
}
function showLogin() {
	var login_in = $(".sitenav_right .pl10");
	if(login_in[0] == undefined){
		$("#dialog-pay").fadeIn(500);
		$("#kaptcha").attr("src","/kaptcha.jpg?" + Math.floor(Math.random() * 100000000));
	}else{
		window.location.reload(true);
	}
}
function showError(msg){
	$("#dialog-line").fadeIn(500);
	$("#dialog-line .login_box span").html("播放提醒");
	$("#dialog-line .login_box .vote").html("<h5 class=\"mb20\" style=\"line-height:24px; padding-bottom:10px;text-align:center;\">"+msg+"</h5>"
		+"<p><a class=\"mr20\" href=\"/help/onlineservice.html\">联系我们</a><a class=\"mr20\" href=\"/help/customercenter.html\">客服中心</a><a href=\"javascript:cancel();\">取消</a></p>");
}
function stopLive(){
	$("#livearea").html("<img src=\"/images/video_bg.png\" width=\"800\" height=\"480\"  alt=\"\"/>");
	$(".tabs_item").html("<img src=\"/images/st_tip_bg.jpg\" width=\"330\" height=\"420\"  alt=\"\"/>");
}
var d = new Date();
setInterval("liveCheck()", 10000);

function liveCheck() {
	var n = new Date();
	if (n - d >300000) {
		$.ajax( {
			type :"GET",
			cache :false,
			url :"/live/livestatus.html?tm=" + new Date(),
			timeout : 10000,
			success : function(data) {
				if (data.errCode == 0) {
					var text=$("#dialog-line .login_box span").text();
					if(text.length>1){
						window.location.reload(true);
					}
				}
				else if (data.errCode == 2) {
					stopLive();
					cancel();
					showLogin();
				}
				else {
					stopLive();
					cancel();
					showError(data.errMsg);
				}
			}
		});
		d = n;
	}
}
